<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>{$site_title}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"><!-- 确保适当的绘制和触屏缩放 -->
    <link rel="stylesheet" href="{$url_css}bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="{$url_css}admin.css" type="text/css">
    <link rel="icon" href="/favicon{SITE_SUFFIX}.ico" type="image/x-icon" />
    <link rel="shortcut icon" href="/favicon{SITE_SUFFIX}.ico" type="image/x-icon" />

    <script type="text/javascript" src="{$url_js}jquery-1.12.0.min.js"></script>
    <script type="text/javascript" src="{$url_js}bootstrap.min.js"></script>
    
    <link rel="stylesheet" href="{$url_css}sweet-alert.css" />
    <script type="text/javascript" src="{$url_js}sweet-alert.min.js"></script>

</head>
<body class="body">
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container-fluid">
              <div class="navbar-header">
                  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                  </button>
                  <a class="navbar-brand" href="admin.php" style="color: white; padding: 9px 15px">
                    <img src="{$url_images}logo-min.png" width="35" height="35" style="display: inline"/>
                </a>
              </div>

              <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                  <ul class="nav navbar-nav">
                      {foreach $menu as $v}
                        <li class="menu-group" pid='{$v.AdminMenuId}'><a href='javascript://'>{$v.Name}</a></li>
                    {/foreach}
                </ul>
                <ul class="nav navbar-right navbar-nav">
                    <li><a href="javascript://" onclick="openuserinfo()">{$admin.AdminUserName}</a></li>
                    <li data-toggle="tooltip" data-placement="bottom" title="刷新页面并重新获取授权"><a href="javascript://" onclick="refreshPower()">刷新权限</a></li>
                    <li data-toggle="tooltip" data-placement="bottom" title="刷新当前标签下的页面"><a href="javascript://" onclick="refresh()">刷新页面</a></li>
                    <li><a href="index.php?do=logout">退出登录</a></li>
                </ul>
                
            </div>
        </div>
    </nav>

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-2 col-lg-2 sidebar">
                {foreach $menu as $v}
                    <div style="display:none" id="menu-group-{$v.AdminMenuId}" class="list-menu" pid="{$v.AdminMenuId}">
                        {foreach $v.child as $v2}
                            <ul class="nav nav-sidebar">
                                <li class="menu-title"><a href="javascript://" style="cursor: default">{$v2.Name}</a></li>
                                {foreach $v2.child as $v3}
                                    <li class="menu-link" mid="{$v3.AdminMenuId}"><a href="{$modules_root}{$v3.Url}">{$v3.Name}</a></li>
                                 {/foreach}
                            </ul>
                        {/foreach}
                    </div>
                {/foreach}
            </div>

            <div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">
                <div class="iframe-nav col-md-12">
                    <ul class="nav nav-tabs" style="padding: 0 40px">
                        <li role="presentation" class="active iframe-title none-close" mid="3"><a href="javascript://">欢迎</a><div class="close">&times;</div></li>
                    </ul>
                </div>

                <div class="iframe">
                    <iframe mid="3" id="rightfr" name="iframe-3" class="iframe-content" height="100%" width="100%" border="0" frameborder="0" src="data/main.php"></iframe>
                </div>
            </div>
        </div>

    </div>

    <!-- 统一弹层 -->
    <div id="adminModal" class="modal bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div id="adminModalWidth" class="modal-dialog modal-lg" style="margin: 100px auto 0 auto">
            <div class="modal-content">

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="$(this).parent().parent().parent().parent().hide()"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="adminModalTitle"></h4>
                </div>
                <div id="adminModalBody" class="modal-body">

                </div>
            </div>
        </div>
    </div>
    <!-- 统一弹层 -->
    <!-- 遮罩层 -->
    <div id='mask_layer' class="sweet-overlay" tabindex="5" style="opacity: 1.09; display: none;"></div>

    <script type="text/javascript">
    {literal}
        function openModal(url, title, width)
        {
            var title = title || '编辑',
                width = width || '900';
            $('#adminModalTitle').html(title);
            $('#adminModalWidth').width(width);

            $('#adminModalBody').html('<iframe onload="initIframeModal()" id="iframemodal" class="iframemodal" src="' + url +'"></iframe>');
            $('#adminModal').modal();
        }
        function initIframeModal()
        {
            var min = Math.min($('#iframemodal').contents().height(), $(window).height()- 300);
            $('#iframemodal').height(min);
        }

        function initIframeModalContent(obj)
        {
            $(obj).contents().find('.modalbox').click(function() {
                top.openModal($(this).attr('modal-url'), $(this).attr('modal-title'), $(this).attr('modal-width'));
            });
        }


        $(".sidebar .list-menu:first").show(0);
        $(".menu-group:first").addClass("active");
        $("div.list-menu:eq(0)").find("ul >li[mid]:eq(0)").addClass("active");
        //初始化iframe
        initiframe();

        function openuserinfo()
        {
            $("li.menu-link a[href$='admin/userinfo.php']").click();
        }

        // 点击菜单
        $(".menu-link").click(function(){
            var href = $(this).find('a').attr("href");
            var mid = $(this).attr("mid");
            var title = $(this).text();
            var sta = false;
            var $ifrmae;
            $(".iframe iframe").each(function(){
                if($(this).attr("mid") == mid){
                    $iframe = $(this);
                    sta = true;
                }
            });

            // 检查现在有多少标签了, 超过10个, 自动关闭第一个
            if ($('li.iframe-title').size() >= 10) {
                $('li.iframe-title:first').find(".close").trigger('click');
            }

            if(sta) {
                //如果存在这个标签
                $iframe.attr("src",href);
                $(".iframe iframe:visible").each(function(){$(this).css({"display":"none"})});//hide other iframe
                $(".iframe iframe[mid='"+mid+"']").css({"display":"inline-block"});
                focusTitle(mid);
            } else {
                //如果不存在，则新建一个
                $(".iframe iframe:visible").each(function(){$(this).css({"display":"none"})});//hide other iframe
                var html = '<iframe onload="initIframeModalContent(this)" name="iframe-'+mid+'" class="iframe-content" height="100%" width="100%" border="0" frameborder="0" src="'+href+'" mid="'+mid+'"></iframe>';
                $(".iframe").append(html);//insert iframe
                html = $('<li role="presentation" class="active iframe-title" mid="'+mid+'"><a href="javascript://">'+title+'</a><div class="close">&times;</div></li>');
                $(".iframe-nav ul").append(html);//insert title
                focusTitle(mid);

                if ($('.iframe-title').length > 1) {
                    $('.iframe-title').removeClass('none-close');
                }
            }
            initiframe();

            return false;
        });

        //关闭按钮事件
        $(document).on('click', ".iframe-title .close", function(){
            var mid = $(this).parent().attr("mid");
            if ($(this).parent().is(".active")){
                var pmid = $(".iframe-title[mid='"+mid+"']").next().attr('mid');
                if (pmid == undefined){
                    pmid = $(".iframe-title[mid='"+mid+"']").prev().attr('mid');
                    $(".iframe iframe[mid='"+mid+"']").prev().css({"display":"inline-block"});//show prev
                }else{
                    $(".iframe iframe[mid='"+pmid+"']").css({"display":"inline-block"});//show next
                }
                focusTitle(pmid);
            }
            
            $(".iframe iframe[mid='"+mid+"']").remove();//remove iframe
            $(this).parent().remove();//remove title
            //不能都关掉
            if ($('.iframe-title').length == 1){
                $('.iframe-title').addClass('none-close');
            }
            return false;

        });

        //点击菜单事件
        $(document).on('click', ".iframe-title a", function(){
            var mid = $(this).parent().attr("mid");
            $(".iframe iframe:visible").each(function(){$(this).css({"display":"none"})});//hide other iframe
            $(".iframe iframe[mid='"+mid+"']").css({"display":"inline-block"});
            focusTitle($(this).parent().attr('mid'));
        })

        
        $(".menu-group").click(function(){
            $(".menu-group").removeClass("active");
            $(this).addClass("active");
            menutoggle($(this).attr("pid"));
            return false;
        });

        //让obj标签高亮
        function focusTitle(mid){
            $(".iframe-title").removeClass('active');
            $(".iframe-title[mid='"+mid+"']").addClass('active');
            $(".menu-link").removeClass("active");
            $(".menu-link[mid='"+mid+"']").addClass('active');
        }

        function refresh()
        {
            $(".iframe iframe:visible").each(function(){
                var name = $(this).attr("name");
                window.frames[name].location.reload();
            });
            return false;
        }

        //刷新权限
        function refreshPower(){
            $.get('admin.php?do=refresh',function(){
                window.location.reload();
            });
        }

        function back()
        {
            $(".iframe iframe:visible:first").each(function(){
                var name = $(this).attr("name");
                window.frames[name].history.go(-1);
            });
            return false;
        }

        function initiframe()
        {
            $(".iframe").css({height:$(window).height()-130});
        }

        function menutoggle(menuid)
        {
            $(".sidebar").find(".list-menu").each(function(){
                $(this).hide(0);
            });
            $(".menu-group").removeClass('active');
            $(".menu-group[pid='"+menuid+"']").addClass('active');
            $("#menu-group-"+menuid).show(0);
            return false;
        }

        $('[data-toggle="tooltip"]').tooltip();

        //以下为公用函数
        function __confirm(msg, desc, url, obj){
            swal({
                title: msg,
                text: desc,
                type: "warning",
                showCancelButton: true,
                cancelButtonText:'取消',
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                closeOnConfirm: true
            }, function(){
                //如果下个页面马上调用swal会导致提示无法显示，故延迟100ms
                setTimeout(function(){
                    obj.location.href = url;
                },100);
            });
        }
        {/literal}
    </script>
</body>
